package com.gxgeek.springweb;

import com.gxgeek.springweb.model.DecryptDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@SpringBootApplication
@RestController
@Slf4j
public class SpringWebApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringWebApplication.class, args);
	}

	@Autowired
	HttpServletRequest request;
	@GetMapping("/hello")
	public String hello(){
		String name = request.getHeader("name");

		log.info(this.getClass().getSimpleName()+" 进入controller");
		log.info(this.getClass().getSimpleName()+" 读取name: {}",name);
		return "success";
	}
	@RequestMapping("/hello1")
	public DecryptDTO hello1(@RequestBody DecryptDTO decryptDTO){
		String name = request.getHeader("name");
		String parameterName = request.getParameter("name");

		log.info(this.getClass().getSimpleName()+" 进入controller");
		log.info(this.getClass().getSimpleName()+" 读取name: {}",name);
		log.info(this.getClass().getSimpleName()+" 读取parameterName: {}",parameterName);
		log.info(this.getClass().getSimpleName()+" 读取decryptDTO: {}",decryptDTO);
		decryptDTO = new DecryptDTO();
		decryptDTO.setB1("1");
		decryptDTO.setB2("2");
		return decryptDTO;
	}
}
